package util;

public class Vector3D {

	private float x, y, z;

	public Vector3D(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
		this.normalize();
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
		this.normalize();
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
		this.normalize();
	}

	public float getZ() {
		return z;
	}

	public void setZ(float z) {
		this.z = z;
		this.normalize();
	}

	public String toString() {
		return "Vector3D[" + x + "," + y + "," + z + "]";
	}

	public void normalize() {
		float length = this.getLength();
		x = x / length;
		y = y / length;
		z = z / length;
	}

	private float getLength() {
		return (float) Math.sqrt(Math.pow(x, 2.0f) + Math.pow(y, 2.0f)
				+ Math.pow(z, 2.0f));
	}

	public float dotProduct(float otherX, float otherY, float otherZ) {
		return (this.x * otherX) + (this.y * otherY) + (this.z * otherZ);
	}

}
